package com.ld.poetry.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.util.StringUtils;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

@AllArgsConstructor
@Getter
public enum CommentStatusEnum {


    WAIT_APPROVAL(0, "待审批"),
    PASSED(1, "审批通过"),
    REJECT(2, "拒绝通过");


    private final Integer code;

    private final String desc;


    public static CommentStatusEnum getEnumByCode(int code) {
        CommentStatusEnum[] values = CommentStatusEnum.values();
        for (CommentStatusEnum typeEnum : values) {
            if (typeEnum.getCode() == code) {
                return typeEnum;
            }

        }
        return null;
    }

    public static CommentStatusEnum getEnumByDesc(String desc) {
        if (StringUtils.hasText(desc)) {
            CommentStatusEnum[] values = CommentStatusEnum.values();
            for (CommentStatusEnum typeEnum : values) {
                if (typeEnum.getDesc().equalsIgnoreCase(desc)) {
                    return typeEnum;
                }
            }
        }
        return null;
    }

    public static Map<Integer, String> getEnumMap() {
        return Arrays.stream(CommentStatusEnum.values()).collect(Collectors.toMap(CommentStatusEnum::getCode, CommentStatusEnum::getDesc));
    }
}
